# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=neon
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.32.4
pkgrel=3
pkgdesc="HTTP and WebDAV client library with a C interface (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://notroj.github.io/neon/"
license=('GPL' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://notroj.github.io/neon/${_realname}-${pkgver}.tar.gz
        0001-m4-check-libintl-functions.patch
        0002-makefile-fix-doc-dir.patch
        neon-0.30.2-mingw-w64.patch)
sha256sums=('b1e2120e4ae07df952c4a858731619733115c5f438965de4fab41d6bf7e7a508'
            '36df51855f6b4047ea668a0ee88c2a119a93654bf9c945d66f8412fd34f947ee'
            '0104d00028a563eddc746539fa5b0085a0dc4e8dc28baa6c71caed374b246903'
            'a1e19dcd755784168542930a0e351506eb1bfc5d941904aa970f81b5b489a95d')
validpgpkeys=('190555472DCC589BEF01609C608A86DF9833CC49') #Joe Orton <joe@manyfish.uk>

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/0001-m4-check-libintl-functions.patch"
  patch -p1 -i "${srcdir}/0002-makefile-fix-doc-dir.patch"
  patch -p1 -i "${srcdir}/neon-0.30.2-mingw-w64.patch"

  ./autogen.sh
  #autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-expat \
    --enable-nls \
    --enable-shared \
    --disable-static \
    --with-ssl=openssl \
    --with-ca-bundle=${MINGW_PREFIX}/etc/ssl/certs/ca-bundle.crt
  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  local PREFIX_WIN=$(cygpath -wm ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/bin/neon-config
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/libneon.la
  sed -s "s|${PREFIX_WIN}|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/neon.pc
}
